home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / comm1 / dnload30.zip / DNLOADPR.WAS < prev    next >
Text File  |  1993-04-22  |  16KB  |  560 lines

  1. ;****Download Pro 3.0 (c) 1993, Michael Lee ***************************
  2. ;**** Log On Procedures (c) 1993, Gregg Hommel                         *
  3. ;**Globals**************************************************************
  4. string filespec,zipath,qwk_work,result,qfile,to_call                  ;*
  5. string newfile,qwkfile,saved_file                                     ;*
  6. string prowin_path=$PWTASKPATH                                        ;*
  7. string prompt_str,start_time,stop_time,name                           ;*  
  8. string delay_time,delay_date,time_is,current_time,current_date        ;*
  9. string M1,M2,C1,B5,B6,zip_to                                                    ;*
  10. integer watchfor,lang=0,graph=0,status3,setjump=0,mxdial,nowdial      ;*  
  11. ;***********************************************************************
  12.  
  13. proc main
  14. integer status2,status1
  15.  
  16. call checkit_out
  17. ;******************
  18. ;The Main Procedure will display the .QWK files for you to choose from.
  19. ;It also let you select the files to download, save to a file and start
  20. ;the log_on procedure.
  21. ; Calls unzip_qwk, show_saved, get_newfiles, dnload, save_file, delay_call
  22. ;******************
  23.  
  24. strfmt S7 "%s\dnload.ini" prowin_path
  25. profilerd S7 "PATH" "storage" C1
  26.   strfmt qwkfile "%s\newfiles.dat" C1
  27.   strfmt newfile "%s\newfiles.txt" C1   ;prowin_path
  28. profilerd S7 "PATH" "qwkpath" filespec
  29.   strfmt M1 "%s\save.fil" C1            ;prowin_path
  30.   strfmt M2 "%s\save.bak" C1            ;prowin_path
  31. setjmp 0 setjump
  32. loop_back:
  33. dialogbox 64 62 148 139 2 "Download Pro V. 2.00"
  34.    pushbutton 50 75 40 14 "&OK" normal
  35.    dirlistbox 20 19 100 49 filespec single qfile
  36.    text  23 6 94 8 left "Please Select .QWK Packet"
  37.    groupbox 22 96 106 33 "Batch Option" shadow
  38.    pushbutton 32 108 88 15 "View Saved File" normal
  39. enddialog
  40.  
  41. status2=$DIALOG
  42. while status2!=10 || status1!=11   ;loop until the eather OK or
  43.   if status2==10                   ;Download Saved pushbutton is choosen.
  44.     call unzip_qwk
  45.    exitwhile
  46.   endif
  47.   if status2==11
  48.      isfile M1
  49.        if success
  50.          call view_file
  51.        else
  52.          usermsg "There are no Saved Files to view!"
  53.      goto loop_back
  54.        endif
  55.    endif
  56.   status2=$DIALOG
  57.  endwhile
  58.  
  59. ;************************
  60. ;This dialog will display the New Files from the selected .QWK 
  61. ;packet. This is where you select the files you would like to 
  62. ;download.
  63. ;************************
  64.  
  65. dialogbox 28 17 304 184 2 "Download File Dialog"
  66.    text  92 10 108 8 left "Please Select Files to Download!"
  67.    flistbox 14 25 274 133 qwkfile multiple newfile
  68.    pushbutton 92 164 40 14 "&OK" normal
  69.    pushbutton 165 164 40 14 "&CANCEL" cancel
  70. enddialog
  71.  
  72.   status3=$DIALOG
  73.     while status3!=10
  74.       status3=$DIALOG
  75.       if status3==1
  76.        exit
  77.       endif
  78.     endwhile
  79. call get_newfiles
  80.  
  81. ;**************************
  82. ;"File Options" lets you Download the file now, save the selected
  83. ;filenames to a file or delay the download for a time you choose.
  84. ;**************************
  85.  
  86. dialogbox 84 49 103 94 2 "File Options"
  87.    pushbutton 20 5 61 22 "&Download Now" normal default
  88.    pushbutton 20 34 61 22 "&Save to File!" normal
  89.    pushbutton 20 64 60 21 "D&elay Download" normal
  90. enddialog
  91.  
  92.                              ;line 50
  93. status1=$DIALOG
  94. while status1!=10 || status1!=11 || status1!=12
  95.   if status1==10
  96.     call dnload
  97.    exitwhile
  98.   endif
  99.   if status1==11
  100.      call save_file
  101.   endif
  102.   if status1==12
  103.      call delay_call
  104.      exitwhile
  105.   endif
  106.   status1=$DIALOG
  107.  endwhile
  108. endproc
  109.  
  110. ;******
  111. ;This proc unzips the .QWK packet.
  112. ;******
  113.  
  114. proc unzip_qwk
  115. profilerd S7 "PATH" "zippath" zipath
  116. profilerd S7 "PATH" "qwkwk" qwk_work
  117. strfmt S1 "%s\pkunzip %s control.dat newfiles.dat -o %s" zipath qfile qwk_work
  118. dos S1 HIDDEN i0   ;using the STRFMT varible S1. This line unzips the control.dat
  119. while istask i0    ;file and newfiles.dat file.
  120. endwhile
  121. endproc
  122.  
  123. ;*******
  124. ;This proc is used to process the results of the Download File Dialog
  125. ;Box. It will strips the filename from the line of text and saves the
  126. ;filename in the Results.txt file. The Newfiles.txt file is the resulting
  127. ;strings from flistbox in the Download File Dialog Box.
  128. ;*******
  129.  
  130. proc get_newfiles
  131. integer idx
  132.   strfmt S6 "%s\newfiles.txt" C1         ;prowin_path
  133.   fopen 3 S6 READ TEXT
  134.     if not success
  135.       usermsg "Could not find newfiles.txt!"
  136.     endif
  137.    strfmt S8 "%s\results.txt" C1         ;prowin_path
  138.   fopen 1 S8 CREATE TEXT
  139.   fclose 1
  140.   fopen 1 S8 READWRITE TEXT
  141.   while not feof 3
  142.    fgets 3 S4
  143.    strfind S4 " " idx    ;looks for a space and places its results in IDX.
  144.     if idx<0             ;I had to add this to prevent an error if theres
  145.       goto jump          ;no End Of File marker in the file.
  146.     endif
  147.    substr result S4 0 idx ;strips the filename from the string
  148.    fputs 1 result         ;writes the results to Results.txt
  149.   endwhile
  150.     jump:
  151.   fclose 1
  152.   fclose 3
  153. endproc
  154.  
  155. ;**********
  156. ;This proc finds the BBS to call and calls log-on with this info.
  157. ;**********
  158.  
  159. proc dnload
  160.  string a1  ;,to_be
  161.  integer index
  162. ;this section opens control.dat file of the .QWK and reads the BBS name
  163. ;the .QWK came from.
  164.   strfmt S9 "%s\control.dat" C1   ;qwk_work
  165.  fopen 4 S9 READ TEXT
  166.   fgets 4 a1
  167.   fgets 4 a1
  168.   fgets 4 a1
  169.   fgets 4 a1
  170.   fgets 4 to_call              ;reads the 5th line from Control.dat to find
  171.   strfind to_call "," index    ;the BBS name this .QWK came from.
  172.   index++
  173.   strdelete to_call 0 index   ;to_call now contains the BBS to call. 
  174.  fclose 4
  175.    call log_on
  176. endproc
  177.  
  178. ;****The Save_file proc looks in your Prowin directory to see if
  179. ; Results.txt has been saved before. If it was, it renames save.fil
  180. ;to save.bak and then renames Results.txt to save.fil.
  181. ;*****
  182. proc save_file
  183.  string B1,B2
  184.  strfmt B1 "%s\SAVE.FIL" C1     ;formats save.fil with your prowin path      
  185.  strfmt B2 "%s\SAVE.BAK" C1     ;formats save.bak with your prowin path      
  186. isfile B1
  187.     if success
  188.       rename B1 B2  ;renames SAVE.FIL to SAVE.BAK
  189.       rename S8 B1  ;renames results.txt to SAVE.FIL
  190.     else
  191.       rename S8 B1  ;same as above
  192.     endif
  193.   exit
  194. endproc
  195.  
  196. ;********
  197. ;This procedure gets the BBS number from the Board.ini file and dials
  198. ;the number.
  199. ;********
  200. proc log_on
  201. string bbs_num1,bbs_num2,bbs_num3
  202. integer max_retry
  203. when target 0 "?" call get_prompt
  204. set modem autobaud on
  205. strfmt B5 "%s\board.ini" prowin_path
  206. strfmt B6 "%s\dnload.ini" prowin_path
  207. profilerd B5 to_call "bbs_number1" bbs_num1
  208. profilerd B5 to_call "bbs_number2" bbs_num2
  209. profilerd B5 to_call "bbs_number3" bbs_num3
  210. profilerd B6 "DIAL" "max_session" mxdial
  211. profilerd B6 "DIAL" "max_retry" max_retry
  212. set dialdir access max_retry
  213. nowdial=0
  214.   while 1
  215.   if mxdial>nowdial
  216. ;usermsg "num3=%s" bbs_num3
  217. ;usermsg "num1=%s num2=%s" bbs_num1 bbs_num2
  218.     if not NULLSTR bbs_num1
  219.        dialnumber bbs_num1
  220.        while $DIALING
  221.        endwhile
  222.           if $CARRIER
  223.              exitwhile
  224.           endif
  225.      endif
  226.     if not NULLSTR bbs_num2
  227. ;usermsg "dialing num2"
  228.        dialnumber bbs_num2
  229.        while $DIALING
  230.        endwhile
  231.           if $CARRIER
  232.              exitwhile
  233.           endif
  234.      endif
  235.     if not NULLSTR bbs_num3
  236. ;usermsg "dialing num3"
  237.        dialnumber bbs_num3
  238.        while $DIALING
  239.        endwhile
  240.           if $CARRIER
  241.              exitwhile
  242.           endif
  243.      endif
  244.      nowdial++
  245.    endif
  246.   endwhile
  247.   watchfor=1
  248.   while watchfor
  249.   endwhile
  250.  clearwhen target 0
  251.  call get_files
  252. endproc
  253.  
  254. ;********
  255. ;This procedure handles all the prompts from a PcBoard BBS and sends the 
  256. ;proper responce to each prompt. 
  257. ;Thanks to Gregg Hommel this proc is available.
  258. ;CALLS chk_prompt
  259. ;********
  260. proc get_prompt
  261.  string user,pasword
  262.  termgets $ROW 0 prompt_str $COL
  263.    if chk_prompt("Command")
  264.       watchfor = 0
  265.    elseif chk_prompt("Enter)=yes?") || chk_prompt("More?") || chk_prompt ("Enter = Yes?")
  266.       transmit "N^M"
  267.    elseif chk_prompt("=no change?") && lang == 0
  268.          transmit "^M"
  269.          lang++
  270.    elseif chk_prompt("Enter)=no?") || chk_prompt("continue?") || chk_prompt("=none?") || chk_prompt("Enter = No?")
  271.       if chk_prompt("graphics") || chk_prompt("Color?") && graph == 0
  272.          transmit "N Q NS^M"
  273.          graph++
  274.       else
  275.          transmit "^M"
  276.       endif
  277.    elseif chk_prompt("Password (Dots")
  278.      profilerd B5 to_call "PASSWORD" pasword
  279.       transmit pasword
  280.       transmit "^M"
  281.    elseif chk_prompt("name?")
  282.      profilerd B5 to_call "USERID" user
  283.      profilerd B5 to_call "PASSWORD" pasword
  284.       transmit USER
  285.       transmit " "
  286.       transmit PASWORD
  287.       transmit "^M"
  288.    elseif chk_prompt("new user?") || chk_prompt("new caller?")
  289.       transmit "r^M"
  290.    endif
  291. endproc
  292.  
  293. func chk_prompt:integer
  294.    strparm chk_out
  295.    strfind prompt_str chk_out
  296.    return FOUND
  297. endfunc
  298.  
  299. ;*********
  300. ;This procedure is used to open the results.txt file and send the filenames
  301. ;to the BBS. It also gets the starting and stop time of the download (used
  302. ;in create_log).
  303. ;CALLS process_file and create_log
  304. ;*********
  305. proc get_files
  306. set dialdir access $DIALENTRY
  307. set cdinxfer yes
  308.   fopen 0 S8 READ TEXT   ;opens newfiles.txt
  309.     if not success
  310.       errormsg "Can't open Results.Txt file!"
  311.     endif
  312.   transmit "d^M"
  313.   while not feof 0   ;loops until the End of file marker is reached.
  314.     fgets 0 S0
  315.     call process_file
  316.   endwhile
  317.   transmit "g^M"
  318.   fclose 0
  319.   time start_time     ;get starting time of download
  320.   strcpy name to_call
  321.   pause 15
  322.   while $CARRIER   ;status==1     ;loop until download is over and BBS Disconnects
  323.     pause 1
  324.   endwhile
  325.   time stop_time      ;get stop time of download
  326.   call create_log
  327. endproc
  328.  
  329. ;**************
  330. ; Process_file accually sends the files to the BBS, using the system 
  331. ;varible S0.   
  332. ;**************
  333.  
  334. proc process_file
  335.   waitfor "none?"
  336.   transmit S0
  337.   transmit "^M"
  338. endproc
  339.  
  340. ;************
  341. ; Create_log creates the log file. It is stored in the Path 
  342. ;"C:\prowin\log\log.txt". (You may need to change the path statement).
  343. ;It also provides the formating of the Log file and inserts the 
  344. ;information in the proper place.
  345. ;***********
  346. proc create_log
  347. string dat,B3
  348.  found_log:
  349.    strfmt B3 "%s\log.txt" C1        ;prowin_path
  350.     chdir C1
  351.       
  352.   findfirst B3                      ;checks to see if log.txt exists.
  353.     if not FOUND                    ;If not found, it creates it.
  354.       usermsg "Log.Txt will now be created!"
  355.       fopen 0 B3 CREATE TEXT
  356.       fclose 0
  357.       goto found_log     ;loops to start of this proc.
  358.     else
  359.       fopen 0 B3 READWRITE TEXT
  360.         strfmt S4 "System Name: %s" name 
  361.         dat=$DATE
  362.         strfmt S1 "Date: %s" dat
  363.         strfmt S2 "Start Time: %s" start_time
  364.         strfmt S3 "Stop Time: %s" stop_time
  365.     fseek 0 0 2   ;\
  366.     fputs 0 " "   ; \
  367.         fputs 0 S4    ;  \
  368.         fputs 0 S1    ;   Write the log the the file.
  369.         fputs 0 S2    ;  /
  370.     fputs 0 S3    ;/
  371.         fputs 0 "Downloaded Files:"
  372.        fopen 1 S8 READ TEXT  ;opens results.txt
  373.          while not feof 1   ;write the filenames to the log.
  374.             fgets 1 S5
  375.         fputs 0 S5
  376.     endwhile
  377.     fclose 1
  378.        endif
  379.       fclose 0     ;closes log.txt
  380.    exit
  381. endproc
  382.  
  383. ;********
  384. ;This procedure handles the delay of the download. It displays the
  385. ;Delayed Download Dialog box along with the updated time every second.
  386. ;It will display until the execution time has been reached.
  387. ;********
  388.  
  389. proc delay_call
  390. integer status,status4
  391. delay_date=$DATE
  392. current_date=$DATE
  393. current_time=$TIME24
  394. dialogbox 82 56 208 110 2 "Delay Execution"
  395.    text  8 16 48 8 left "Current Time:"
  396.    vtext 53 16 33 8 left current_time
  397.    text  105 16 49 8 left "Current Date:"
  398.    vtext 155 16 35 10 left current_date
  399.    groupbox 6 5 194 27 "Current Time & Date" shadow
  400.    editbox 137 41 35 12 delay_time 9
  401.    text  33 43 102 8 left "Enter Start Time (HH:MM:SS):"
  402.    text  33 60 105 8 left "Enter New Date (MM/DD/YY):"
  403.    editbox 137 59 35 12 delay_date 9
  404.    pushbutton 48 83 40 15 "&OK" normal default
  405.    pushbutton 113 83 40 15 "&Cancel" cancel
  406. enddialog
  407.  
  408.  status=$DIALOG
  409.   while status!=10 || status!=1
  410.    status=$DIALOG
  411.     if status==1
  412.      exit
  413.     endif
  414.     if status==10
  415.       exitwhile
  416.     endif
  417.   endwhile
  418.   destroydlg
  419.  
  420. dialogbox 106 70 137 83 2 "Delayed Download"
  421.    vtext 74 9 44 8 left time_is
  422.    text  26 9 48 8 left "Current Time:"
  423.    text  26 24 56 8 left "Execution Time:"
  424.    vtext 87 25 44 10 left delay_time
  425.    text  26 38 57 8 left "Execution Date:"
  426.    vtext 87 38 45 8 left delay_date
  427.    pushbutton 49 56 40 14 "E&xit" normal
  428. enddialog
  429.  
  430.    status4=$DIALOG
  431.   while 1               ;loops until the execution time has been reached.
  432.    status4=$DIALOG
  433.    current_time=$TIME24
  434.    current_date=$DATE
  435.     if status4==10      ;if exit is selected, Exit.
  436.       destroydlg
  437.       exitwhile
  438.     endif
  439.    strcmp current_date delay_Date      ;compare current and delay times.
  440.       if $strcmp == 0                  
  441.          strcmp current_time delay_Time   ;if date and time match, exit loop.
  442.          if $strcmp == 0               
  443.             exitwhile
  444.             destroydlg                 
  445.          endif                         
  446.       endif
  447.       if $strcmp!=0
  448.        updatedlg 64
  449.       endif
  450.     time_is=current_time
  451.    endwhile
  452.   destroydlg
  453.  call dnload
  454. endproc
  455.  
  456. ;*********************
  457. ;"View File" will display the Files that you have saved (Save.fil and/or save.bak)
  458. ;If you select "View Next" from the Dialog, it first checks to see if
  459. ;SAVE.BAK is there. If not, it will display a message "No more files to view!",
  460. ;If SAVE.BAK is on the disk, it will display that file. It will switch 
  461. ;between these two files (for each click of "View Next") until you eather
  462. ;Choose "Download Files" or "CANCEL". "Download Files" will proceed with
  463. ;the download of the files Displayed. "CANCEL" will go back to the main
  464. ;Dialog "Download Pro".
  465. proc view_file
  466. integer status9
  467.  strcpy saved_file M1   ;copy Save.fil (M1) to saved_file.
  468.  
  469. loop_save:
  470. dialogbox 72 34 196 149 2 "Saved File Viewer"
  471.    text  13 12 28 8 left "Viewing:"
  472.    vtext 44 12 65 8 left saved_file
  473.    pushbutton 136 9 40 14 "View Next" normal
  474.    ftext 34 32 134 73 saved_file
  475.    pushbutton 60 110 79 13 "Download Files" normal
  476.    pushbutton 61 129 77 13 "&CANCEL" cancel
  477. enddialog
  478.  
  479.   status9=$DIALOG
  480.   while status9!=1    ;loop unless CANCEL is selected.
  481.     status9=$DIALOG
  482.      if status9==11
  483.       isfile S8               ;looks for results.txt.
  484.         if success            ;if found
  485.         delfile S8        ;deleted it.
  486.         endif
  487.             copyfile saved_file S8    ;copies selected files to results.txt.
  488.          strcmp saved_file M1    ;compares saved_file to SAVE.FIL
  489.               if success        ;if the same, proceed.
  490.             delfile M1        ;delete SAVE.FIL
  491.             isfile M2        ;looks for SAVE.BAK
  492.                if success    
  493.                rename M2 M1    ;rename SAVE.BAK to SAVE.FIL
  494.              ;delfile M2    
  495.                endif
  496.           else             
  497.              delfile M2
  498.           endif
  499.       call dnload
  500.       endif
  501.      if status9==10
  502.         strcmp saved_file M1
  503.               if success
  504.             isfile M2
  505.             if success
  506.                strcpy saved_file M2
  507.             else
  508.                usermsg "No more Files to view!"
  509.                goto loop_save
  510.             endif
  511.         else
  512.             strcpy saved_file M1
  513.         endif
  514.        goto loop_save
  515.     endif
  516.    endwhile
  517.       if status9==1
  518.          longjmp 0 setjump           ;if CANCEL is selected, jump to main
  519.       endif                ;Dialog.
  520. endproc
  521.  
  522. proc checkit_out
  523. integer test1=0,test2=0,test3=0
  524. string miss1,miss2,miss3
  525. strfmt B5 "%s\board.ini" prowin_path
  526. strfmt B6 "%s\dnload.ini" prowin_path
  527. strfmt S7 "%s\dnload.ini" prowin_path
  528. profilerd S7 "PATH" "storage" C1
  529. profilerd S7 "PATH" "zip_to" zip_to
  530. profilerd S7 "PATH" "qwkwk" qwk_work
  531.  
  532. if not chdir C1
  533.   usermsg "no C1"
  534.   test1=1
  535. endif
  536. if not chdir zip_to
  537.   usermsg "no zip_to"
  538.   test2=1
  539. endif
  540. if not chdir qwk_work
  541.   usermsg "No qwk_work"
  542.   test3=1
  543. endif
  544. if test1!=0 || test2!=0 || test3!=0
  545.  if test1!=0
  546.   miss1="Download Pro Storage Path:"
  547.  endif
  548.   if test2!=0
  549.     miss2="Unzip To Path"
  550.   endif
  551.   if test3!=0
  552.       miss3="Mail Packet Working Path"
  553.   endif
  554.  errormsg "The Following Paths are not setup:%s %s %s" miss1 miss2 miss3
  555.  exit
  556. endif
  557.  
  558. endproc
  559.  
  560.